[#ftl]

[#-- macro getLocalVariable of a config Start--]
[#macro getLocalVariable configModel1 listOfLocalVariables resultList]
    [#if configModel1.methods??]
        [#assign methodList1 = configModel1.methods]
    [#else]
        [#assign methodList1 = configModel1.libMethod]
    [/#if]
    [#list methodList1 as method][#-- list methodList1 --]
        [#if method.callBackMethod=="false"]
            [#list method.arguments as argument][#-- list method.arguments --]
                [#if (argument.genericType == "struct")][#-- if struct --]
                    [#if argument.context??][#-- if argument.context?? --]
                        [#if argument.context!="global"] [#-- if global --]
                            [#assign varName= " "+argument.name]
                            [#assign ll= listOfLocalVariables?split(" ")]
                            [#assign exist=false]
                            [#list ll as var]
                                [#if var==argument.name]
                                    [#assign exist=true]
                                [/#if]
                            [/#list]
                            [#if !exist]  [#-- if exist --]
                                [@addTab nb=1 /]
                                ${argument.typeName} ${argument.name};
                                [#assign resultList = listOfLocalVariables + " "+ argument.name]
                            [/#if][#-- if exist --]
                        [/#if][#-- if global --]
                    [#else][#-- if context?? --]
                        [@addTab nb=1 /]
                        ${argument.typeName} ${argument.name};
                    [/#if][#-- if argument.context?? --]

                    [#-- Array type --]
                    [#list argument.argument as subArg] [#-- list subArg --]
                        [#if subArg.genericType=="Array"] [#-- if genericType == "Array" --]
                            ${subArg.typeName} ${subArg.name}[${subArg.arraySize}] ;
                        [/#if] [#-- if genericType == "Array" --]
                        [#if subArg.genericType =="struct"]
                            [#list subArg.argument as subArg1] [#-- list subArg1 --]
                                [#if subArg1.genericType=="Array"] [#-- if genericType == "Array" --]
                                    [@addTab nb=1 /]
                                    [#t] ${subArg1.typeName} ${subArg1.name}[${subArg1.arraySize}] ;
                                [/#if] [#-- if genericType == "Array" --]
                            [/#list]
                        [/#if]
                    [/#list] [#-- list subArg --]
                [/#if][#-- if struct --]

                [#if argument.genericType == "simple"]
                    [#compress]
                    [#if argument.addressOf]
                        [#assign adr = "&"]
                    [#else ]
                        [#assign adr = ""]
                    [/#if]
                    [/#compress]
                    [#if argument.context??]
                        [#if argument.context!="global" && argument.status!="NULL"]
                            [#assign varName= " " + argument.name]
                            [#if (argument.init=="false")]
                                [@addTab nb=1 /]
                                ${argument.typeName} ${argument.name};
                            [#else]
                                [@addTab nb=1 /]
                                ${argument.typeName} ${argument.name} = ${adr}${argument.value};
                            [/#if]
                        [/#if]
                    [/#if]
                [/#if]

            [/#list][#-- list method.arguments --]
        [/#if]
    [/#list][#-- list methodList1 --]
[/#macro]
[#-- macro getLocalVariable of a config End--]

[#-- macro generateConfigModelCode --]
[#macro generateConfigModelCode configModel inst nTab]
    [#if configModel.comments??]
        [@addTab nb=1 /]
        /**${configModel.comments} #n#t*/
    [/#if]
    [#if configModel.methods??] [#-- if the pin configuration contains a list of LibMethods--]
        [#assign methodList = configModel.methods]
    [#else]
        [#assign methodList = configModel.libMethod]
    [/#if]
    [#local myInst=inst]

    [#list methodList as method]
        [#-- #if !FREERTOS?? || method.osCall=="PRE_OS"--]
            [#assign args = ""]
            [#if method.callBackMethod=="false"]
                [#if method.status=="OK"]
                    [#assign return = ""]
                    [#if method.arguments??]
                        [#list method.arguments as fargument]
                            [#if fargument.returnValue=="false"]
                                [#compress]
                                    [#if fargument.addressOf]
                                        [#assign adr = "&"]
                                    [#else ]
                                        [#assign adr = ""]
                                    [/#if]
                                [/#compress]
                                [#if fargument.genericType == "Array"]
                                    [#assign valList = fargument.value?split(fargument.arraySeparator)]
                                    [#assign i = 0]
                                    [#list valList as val]
                                        [@addTab nb=1 /]
                                        ${fargument.name}[${i}] = ${val};
                                        [#assign i = i+1]
                                    [/#list]
                                    [#assign argValue="&"+fargument.name]
                                [/#if]
                                [#if fargument.genericType == "struct"]
                                    [#if fargument.context??]
                                        [#if fargument.context=="global"]
                                            [#if configModel.ipName=="DMA"]
                                                [#assign instanceIndex = "_" + configModel.instanceName?lower_case]
                                            [#else]
                                                [#assign instanceIndex = inst?replace(name,"")]
                                            [/#if]
                                        [/#if]
                                    [/#if]
                                    [#if instanceIndex??&&fargument.context=="global"]
                                        [#assign arg = "" + adr + fargument.name + instanceIndex]
                                    [#else]
                                        [#assign arg = "" + adr + fargument.name]
                                    [/#if]
                                    [#-- [#assign arg = "" + adr + fargument.name] --]
                                    [#--if (!method.name?contains("Init")&&fargument.context=="global")--]
                                    [#if (fargument.init=="false")] [#-- MZA add the field init for Argument object, if init is false the initialization of this argument is not done --]
                                        [#-- do Nothing --]
                                    [#else]
                                        [#list fargument.argument as argument]
                                            [#compress]
                                                [#if argument.addressOf]
                                                    [#assign AdrMza = ""]
                                                [#else]
                                                    [#assign AdrMza = ""]
                                                [/#if]
                                            [/#compress]
                                            [#if argument.genericType != "struct"]
                                                [#if argument.mandatory]
                                                    [#if instanceIndex??&&fargument.context=="global"]
                                                        [#assign argValue=argument.value?replace("$Index",instanceIndex)]
                                                    [#else]
                                                        [#assign argValue=argument.value]
                                                    [/#if]
                                                    [#if argument.genericType=="Array"][#-- if genericType=Array --]
                                                        [#assign valList = argument1.value?split(argument1.arraySeparator)]
                                                        [#assign i = 0]
                                                        [#list valList as val]
                                                            [@addTab nb=1 /]
                                                            ${argument1.name}[${i}] = ${val};
                                                            [#assign i = i+1]
                                                        [/#list]
                                                    [/#if] [#-- if genericType=Array --]
                                                    [@addTab nb=nTab /]
                                                    [#if instanceIndex??&&fargument.context=="global"]
                                                        [#t]${fargument.name}${instanceIndex}
                                                    [#else]
                                                        [#t]${fargument.name}
                                                    [/#if]
                                                    [#t].${argument.name} = ${argValue};
                                                [#else]
                                                    [#assign argValue = AdrMza + Function]
                                                    [#if argument.genericType=="fpointer"]
                                                        [#local Function = inst + "_" + argument.name]
                                                    [#else]
                                                        [#if argument.value??]
                                                            [#local Function = argument.value]
                                                        [/#if]
                                                    [/#if]
                                                    [@addTab nb=nTab /]
                                                    [#if instanceIndex??&&fargument.context=="global"]
                                                        [#t]${fargument.name}${instanceIndex}
                                                    [#else]
                                                        [#t]${fargument.name}
                                                    [/#if]
                                                    [#t].${argument.name} = ${argValue};
                                                    [#--[#if argument.name=="Instance"]--]
                                                        [#-- [#if nTab==2]#t#t[#else]#t[/#if][#if instanceIndex??&&fargument.context=="global"]${fargument.name}${instanceIndex}[#else]${fargument.name}[/#if].${argument.name} = ${AdrMza}${Function};--]
                                                    [#--[/#if]--]
                                                [/#if]
                                            [#else]
                                                [#list argument.argument as argument1]
                                                    [#if argument1.mandatory]
                                                        [#if instanceIndex??&&fargument.context=="global"]
                                                            [#assign argValue=argument1.value?replace("$Index",instanceIndex)]
                                                        [#else]
                                                            [#assign argValue=argument1.value]
                                                        [/#if]
                                                        [#if argument1.genericType=="Array"][#-- if genericType=Array --]
                                                            [#assign valList = argument1.value?split(":")]
                                                            [#assign i = 0]
                                                            [#list valList as val]
                                                                [@addTab nb=1 /]
                                                                ${argument1.name}[${i}] = ${val};
                                                                [#assign i = i+1]
                                                            [/#list]
                                                            [#assign argValue="&"+argument1.name+"[0]"]
                                                        [/#if] [#-- if genericType=Array --]
                                                        [@addTab nb=nTab /]
                                                        [#if instanceIndex??&&fargument.context=="global"]
                                                            [#t]${fargument.name}${instanceIndex}
                                                        [#else]
                                                            [#t]${fargument.name}
                                                        [/#if]
                                                        [#t].${argument.name}.${argument1.name} = ${argValue};
                                                    [/#if]
                                                [/#list]
                                            [/#if]
                                        [/#list][#-- list  fargument.argument as argument--]
                                    [/#if]
                                [#elseif fargument.genericType == "simple"] [#-- MZA if argument is simple we pass the name of the argument and not the value --]
                                    [#if fargument.context=="global"]
                                        [#assign arg = "" + adr + fargument.name + myInst]
                                    [#else]
                                        [#assign arg = "" + adr + fargument.name]
                                    [/#if]
                                [#else][#-- if struct --]
                                    [#assign arg = "" + adr + fargument.value]
                                [/#if]
                                [#if args == ""]
                                    [#assign args = args + arg ]
                                [#else]
                                    [#assign args = args + ', ' + arg]
                                [/#if]
                            [#else] [#-- here we have an Argument as Return Value --]
                                [#if fargument.context=="global"]
                                    [#assign return = fargument.name + myInst + " = "]
                                [#else]
                                    [#assign return = fargument.name + " = "]
                                [/#if]
                            [/#if]
                        [/#list]
                        #n[@addTab nb=nTab /][#t]
                        [#t]${return}${method.name}(${args});#n
                    [#else]
                        #n[@addTab nb=nTab /][#t]
                        [#t]${return}${method.name}();#n
                    [/#if]
                [#else] [#-- [/#if] [#if method.status=="KO"] --]
                    #n[@addTab nb=nTab /]
                    [#t]//!!! ${method.name} is commented because some parameters are missing
                    [#if method.arguments??]            [#-- here we comment all variables initialization --]
                        [#list method.arguments as fargument]
                            [#if fargument.addressOf]
                                [#assign adr = "&"]
                            [#else ]
                                [#assign adr = ""]
                            [/#if]
                            [#if fargument.genericType == "struct"]
                                [#assign arg = "" + adr + fargument.name]
                                [#if fargument.context??]
                                    [#if fargument.context=="global"]
                                        [#if configModel.ipName=="DMA"]
                                            [#assign instanceIndex = "_"+ configModel.instanceName?lower_case]
                                        [#else]
                                            [#assign instanceIndex = inst?replace(name,"")]
                                        [/#if]
                                    [/#if]
                                [/#if]
                                [#if instanceIndex??&&fargument.context=="global"]
                                    [#assign arg = "" + adr + fargument.name + instanceIndex]
                                [#else]
                                    [#assign arg = "" + adr + fargument.name]
                                [/#if]
                                [#if (!method.name?contains("Init")&&fargument.context=="global")]
                                [#else]
                                    [#list fargument.argument as argument]
                                        [#if argument.genericType != "struct"]
                                            [#if argument.mandatory]
                                                [#if instanceIndex??&&fargument.context=="global"]
                                                    [#assign argValue=argument.value?replace("$Index",instanceIndex)]
                                                [#else]
                                                    [#assign argValue=argument.value]
                                                [/#if]
                                                [@addTab nb=nTab /]
                                                [#t]//
                                                [#if instanceIndex??&&fargument.context=="global"]
                                                    [#t]${fargument.name}${instanceIndex}
                                                [#else]
                                                    [#t]${fargument.name}
                                                [/#if]
                                                [#t].${argument.name} = ${argValue};
                                             [#else]
                                                [#if argument.name=="Instance"]
                                                    [@addTab nb=nTab /]
                                                    [#t]//
                                                    [#if instanceIndex??&&fargument.context=="global"]
                                                        [#t]${fargument.name}${instanceIndex}
                                                    [#else]
                                                        [#t]${fargument.name}
                                                    [/#if]
                                                    [#t].${argument.name} = ${inst};
                                                [/#if]
                                            [/#if]
                                        [#else]
                                            [#list argument.argument as argument1]
                                                [#if argument1.mandatory]
                                                    [#if instanceIndex??&&fargument.context=="global"]
                                                        [#assign argValue=argument1.value?replace("$Index",instanceIndex)]
                                                    [#else]
                                                        [#assign argValue=argument1.value]
                                                    [/#if]
                                                    [@addTab nb=nTab /]
                                                    [#t]//
                                                    [#if instanceIndex??&&fargument.context=="global"]
                                                        [#t]${fargument.name}${instanceIndex}
                                                    [#else]
                                                        [#t]${fargument.name}
                                                    [/#if]
                                                    [#t].${argument.name}.${argument1.name} = ${argValue};
                                                [/#if]
                                            [/#list]
                                        [/#if]
                                    [/#list]
                                [/#if]
                            [#else]
                                [#assign arg = "" + adr + fargument.value]
                            [/#if]
                            [#if args == "" && fargument.returnValue!="true"]
                                [#assign args = args + arg ]
                            [#else]
                                [#assign args = args + ', ' + arg]
                            [/#if]
                        [/#list]
                        #n[@addTab nb=nTab /][#t]
                        [#t]//${method.name}(${args});#n
                    [#else]
                        #n[@addTab nb=nTab /][#t]
                        [#t]${method.name}()#n;
                    [/#if]
                [/#if]
            [/#if]
        [#-- /#if ---]
    [/#list]

    [#assign instanceIndex = ""]
    [#-- else there is no LibMethod to call--]

[/#macro]
[#-- End macro generateConfigModelCode --]

[#-- macro addTab, add nb tabulations --]
[#macro addTab nb=1]
    [#list 1..nb as i]
        #t[#t]
    [/#list]
[/#macro]
[#-- End macro addTab --]
